package com.yuexun.beilunpatient.ui.test.ui;

import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.yuexun.beilunpatient.R;
import com.yuexun.beilunpatient.base.BaseKJActivity;
import com.yuexun.beilunpatient.config.AppConfig;
import com.yuexun.beilunpatient.ui.test.adapter.TestDetailAdapter;
import com.yuexun.beilunpatient.ui.test.bean.AssayDtlRowSet;
import com.yuexun.beilunpatient.ui.test.model.impl.TestDetaiModel;
import com.yuexun.beilunpatient.ui.test.presenter.impl.TestDetaiPresenter;
import com.yuexun.beilunpatient.ui.test.ui.view.ITestDetailView;
import com.yuexun.beilunpatient.widget.EmptyLayout;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;
import org.kymjs.kjframe.utils.SystemTool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2018/3/30 0030.
 */

public class Act_Test_Detail extends BaseKJActivity implements ITestDetailView {

    @Bind(R.id.act_testdetail_list)
    public ListView act_testdetail_list;
    @Bind(R.id.empty_layout)
    public EmptyLayout mEmptyLayout;
    @Bind(R.id.act_testdetail_num)
    public TextView act_testdetail_num;

    //申请单号
    private String rpeportNo;
    private String hospId;

    private TestDetaiPresenter presenter;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_test_detail);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        presenter = new TestDetaiPresenter(this, new TestDetaiModel());
        rpeportNo = getIntent().getExtras().getString("rpeportNo");
        hospId = getIntent().getExtras().getString("hospId");
        mEmptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
            }
        });

        ApiGetData();
    }

    /**
     * 请求数据
     */
    private void ApiGetData() {
        if (SystemTool.checkNet(aty)) {
            Map<String, String> params = new HashMap<>();
            params.put("rpeportNo", rpeportNo);
            params.put("hospId", hospId);
            params.put("pageIndex", 1+"");
            params.put("pageSize", 99999+"");
            params.put("sessionUuidPatient", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
            presenter.inquireAssayDetail(params);
        } else {
            ViewInject.toast("网络异常，请检查网络是否连接!");
        }
    }

    @OnClick(R.id.title_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void showTestDetail(ArrayList<AssayDtlRowSet> list) {
        if(list != null && list.get(0).getCode() == 1){
            TestDetailAdapter adapter = new TestDetailAdapter(act_testdetail_list, list.get(0).getRows(), R.layout.item_test_detail);
            act_testdetail_list.setAdapter(adapter);
            act_testdetail_num.setText("单号:" + rpeportNo);
        }
        mEmptyLayout.dismiss();
    }
}
